package com.fashiontextile.user.feign.fallback;

import com.fashiontextile.common.entity.R;
import com.fashiontextile.user.entity.Image;
import com.fashiontextile.user.entity.Role;
import com.fashiontextile.user.entity.User;
import com.fashiontextile.user.feign.UserClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author brooke_zb
 */
@Slf4j
@Component
public class UserClientFallbackFactory implements FallbackFactory<UserClient> {
    @Override
    public UserClient create(Throwable cause) {
        log.warn("用户接口已降级", cause);
        return new UserClient() {
            @Override
            public R<User> getUserByUid(long uid) {
                return R.fail("服务器出现问题，获取失败");
            }

            @Override
            public R<User> getUserByUsername(String username) {
                return R.fail("服务器出现问题，获取失败");
            }

            @Override
            public R<User> getUserByEmail(String email) {
                return R.fail("服务器出现问题，获取失败");
            }

            @Override
            public R<?> insertUser(User user) {
                return R.fail("服务器出现问题，注册失败");
            }

            @Override
            public R<Role> getRoleByRid(Integer rid) {
                return R.fail("服务器出现问题，注册失败");
            }

            @Override
            public R<Role> getRoleByName(String name) {
                return R.fail("服务器出现问题，注册失败");
            }

            @Override
            public R<?> changeRoleByUid(@PathVariable("uid") long uid,@PathVariable("rid")Integer rid) {
                return R.fail("服务器出现问题，注册设计师失败");
            }

            @Override
            public R<?> getImageById(Long pointTo, Long diid) {
                return R.fail("服务器出现问题，获取失败");
            }

            @Override
            public R<?> uploadImage(Long diid, MultipartFile picture) {
                return R.fail("服务器出现问题，上传失败");
            }

            @Override
            public R<?> uploadImage(List<Image> images) {
                return R.fail("服务器出现问题，上传失败");
            }

            @Override
            public R<?> deleteImageByPointTo(Long pointTo, Long diid) {
                return R.fail("服务器出现问题，删除失败");
            }

            @Override
            public R<?> deleteImageById(Long id) {
                return R.fail("服务器出现问题，删除失败");
            }
        };
    }
}
